cmake_minimum_required(VERSION 3.12)

project("tinybpt")

find_package(nlohmann_json REQUIRED QUIET)

if(NOT nlohmann_json_FOUND)
    set(NLOHMANN_JSON_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/include/nlohmann)
else()
    set(NLOHMANN_JSON_INCLUDE_DIR ${nlohmann_json_INCLUDE_DIRS})
endif()

file(GLOB SRC_FILES src/*.cpp)

if(UNIX AND NOT APPLE)
    message(STATUS "Building for Linux")
    add_executable(tinybpt ${SRC_FILES})
    target_include_directories(tinybpt PRIVATE "include" ${NLOHMANN_JSON_INCLUDE_DIR})
    
    # Adding Linux-specific installation rules
    install(TARGETS tinybpt DESTINATION bin)
    install(FILES tinybpt_db.json DESTINATION /etc/tinybpt)
    install(FILES tinybpt.sh DESTINATION /etc/profile.d)
    install(DIRECTORY DESTINATION /var/cache/tinybpt)
else()
    message(FATAL_ERROR "Unsupported platform")
endif()